package com.niit.order.pojo;

import com.niit.order.myImpl.ConcreteCommand;
import rx.Observable;
import rx.Subscriber;

/**
 * 客户端
 *
 * @author yaojianfeng
 */
public class Client {
    public static void main(String[] args) {
        Client client = new Client();
//        client.invokerTest();
        client.observableTest();

    }

    public void observableTest() {
        //创建事件源
        Observable<String> objectObservable = Observable.create(new Observable.OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {
                subscriber.onNext("Hello RxJava");
                subscriber.onNext("I am Jeff");
                subscriber.onCompleted();
            }
        });
        //创建订阅者
        Subscriber<String> subscriber = new Subscriber<String>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onNext(String str) {
                System.out.println("Subscriber: " + str);
            }
        };
        //订阅
        objectObservable.subscribe(subscriber);

    }

    public void invokerTest() {
        Receiver receiver = new Receiver();
        ConcreteCommand command = new ConcreteCommand(receiver);
        Invoker invoker = new Invoker();
        invoker.setCommand(command);
        //客户端通过调用者来执行命令
        invoker.action();
    }


}
